home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / ViewIt™ 2.24 Shareware / FaceWare / FaceWare.rsrc / TEXT_1281_U8. Memory Utilities.txt < prev    next >
Text File  |  1994-04-10  |  6KB  |  49 lines

  1. U8. Memory Utility Commands
  2.   ViewIt supports commands that can be used to check free memory, dynamically allocate blocks, remove modules from memory, and clean up memory when quitting from within environments such as HyperCard.
  3.   FaceWare's approach to heap memory management makes use of a minimum "buffer" of free memory that all modules attempt to maintain.  The size in bytes of this buffer is saved in fHeapBuff, which has a default value of 16384 bytes (16K).  The value of fHeapBuff can be changed by the program at any time after DoInit is called, although 16K is sufficient for most programs.  You should think of fHeapBuff as representing the size of a shared pool of heap memory used for disk-based resource swapping under low memory conditions (i.e. memory into which fonts and other purgeable resources can be swapped).
  4.   FaceWare modules attempt to maintain at least fHeapBuff bytes of free heap memory by calling ChkMem or NewBlk before each action that would consume significant amounts of free memory.  Note that this scheme does not protect the main program from making its own mistakes, and so we recommend that it too make use of ChkMem or NewBlk (or an equivalent scheme) when attempting to allocate large blocks of memory.
  5.  
  6. Name  Number  Parameters & Variables used
  7. ChkMem  171  a,b,c,uResult
  8.   Attempts to find a contiguous block of free memory at least a + fHeapBuff bytes in size.  If necessary, ChkMem will, in succession, compact memory, purge memory, request memory from other modules, and move the clipboard to disk until a contiguous block equal to or larger than the specified size is found.
  9.   The extent of the operations performed when searching for free memory can be optionally restricted via parameter b (= sum of following bit values):
  10.    0 = no restrictions
  11.    1 = don't remove purgeable blocks
  12.    2 = don't request memory from other modules
  13.    4 = don't move the clipboard to disk
  14. Parameter c can be optionally used to designate a number of bytes to use in place of fHeapBuff (i.e., if c > 0,  a + c becomes the target block size).
  15.   The size in bytes of the largest contiguous block that is safe to allocate (= largest block - fHeapBuff) is returned in uResult.  Thus a program calling ChkMem can simply check to see whether uResult ‚â• a upon return.
  16.   A good way to think of parameter a is to view it as a gauge of how much work you are asking ChkMem to do.  Small values will be easy to satisfy, require few changes to the heap, and return the smallest values of uResult.  Larger values of a can ultimately force all purgeable blocks from the heap, and return the largest possible value of uResult.
  17.   WARNING:  Unlike most other utility commands, ChkMem does not preserve the "w" and "c" variables in fRec.
  18.  
  19. NewBlk  172  a,b,c,uResult
  20.   Performs a ChkMem and, if at least a free bytes can be safely allocated, creates a new relocatable block, moves it high in the heap, locks it down, and returns a handle to the block in uResult.  If unsuccessful, uResult is set equal to zero. Use the toolbox call DisposHandle to later remove such a block from memory.  Parameters b and c have the same meaning as described above for ChkMem.
  21.   For example, the following code allocates an 80,000 byte block and saves its handle in "myHandle" (Pascal source),
  22.   FaceIt(nil,NewBlk,80000,0,0,0);
  23.   if (uResult <> 0) then
  24.    begin
  25.     myHandle := Handle(uResult);
  26.     [do something with the block]
  27.     DisposHandle(myHandle);
  28.    end
  29. where the address of the block would be given by myHandle^ [Pascal], *myHandle [C], or long(myHandle) [FORTRAN].
  30.   WARNING:  Unlike most other utility commands, NewBlk does not preserve the "w" and "c" variables in fRec.
  31.  
  32. PrgCmd  173  a
  33.   Attempts to unlock the FCMD and/or FACE resource(s) belonging to the module(s) designated by a.  Unlocking such resources will make them purgeable so that the memory they occupy can be used for other purposes.
  34.   a = scope of FCMD/FACE resources in use by the main program that are to be unlocked (made purgeable)
  35.    0 = all FCMD/FACE resources in System & Appl. Heaps
  36.    1 = all FCMD/FACE resources in System Heap
  37.    2 = all FCMD/FACE resources in Application Heap
  38.    <32768 = resource ID of a single FCMD/FACE resource
  39.    other = address of single shared record (single instance)
  40. PrgCmd will fail to unlock an FCMD or FACE resource if a shared record associated with the resource exists which is not included in the scope of a, or if the resource's purge bit is not set.   For example, if a main program requested that an FCMD be unlocked (made purgeable), then this would not be done if the FCMD was part of the System file and was, at the same time, being used by another program.
  41.   The most common use of PrgCmd is to unload as many FaceWare modules as possible before performing a program operation that makes use of the recovered heap memory:
  42.   FaceIt(nil,PrgCmd,2,0,0,0);
  43. The next call to the "FaceIt" dispatching procedure will then reload any necessary FaceWare modules.  WARNING:  If you unload all FaceWare modules, consume most of the heap space, and then make a "FaceIt" call, you won't have enough memory to reload FaceWare modules!  Thus the best use of PrgCmd is to recover memory for temporary purposes so that it can be released again before reloading modules.
  44.   Finally, note that some modules include FACE and other resource types that are loaded by the module itself (vs. LoadIt), meaning that PrgCmd will have no effect on such resources.  In these cases a module-specific command will often be provided to directly unload such resources.
  45.   MODULE DEVELOPERS:  If using PrgCmd from within a FaceWare module, be careful not to unload any modules that were used to call the module that is executing PrgCmd, nor execute code that moves memory after calling PrgCmd to unload one's self.
  46.  
  47. DoUnld  -63  [none]
  48.   Cleans up FaceWare's use of current application heap by (1) closing all open ViewIt windows, (2) disposing of all blocks in the heap that were dynamically allocated by ViewIt when DoInit was first called, and (3) calling PrgCmd with a = 2 to unload all FaceWare modules.
  49.   DoUnld is useful in high-level environments where programs can be exited without quitting to the Finder (such as when switching stacks within HyperCard).  WARNINGS:  Do not call DoUnld from within programs that make use of the FaceIt module, and do not make any calls to the "FaceIt" dispatching procedure after calling DoUnld.